package java基础.method;

/**
 * @author IT_Jay
 * @date 2022/1/16 10:01
 */

public class Demo04 {
    public static void main(String[] args) {
        Demo04 demo04 = new Demo04();
        //一个方法只能指定一个可变参数
//        demo04.test(1,2,3,4,5,6);
        printMax(34,1.0,3.14,999);
        printMax(new double[]{1,2,3});
    }

    public void test(int x,int... i){       //可变参数必须放在最后
        System.out.println(i[0]);
        System.out.println(i[1]);
        System.out.println(i[2]);
        System.out.println(i[3]);
        System.out.println(i[4]);
        System.out.println(i[5]);
    }
    public void method(){}
    public void method(int i){}
    public void method(int i, int i2){}
    public void method(int i, double d){}

    //定义一个方法，找出最大值
    public static void printMax(double... numbers){
        if (numbers.length==0){
            System.out.println("no argument passed");
            return;
        }
        double result =numbers[0];
        //排序
        for (int i = 1; i < numbers.length; i++) {
            if (numbers[i]>result){
                result= numbers[i];
            }
        }
        System.out.println("最大值是:\n"+result);
    }
}
